/*
https://leetcode-cn.com/problems/card-flipping-game/solution/fan-zhuan-qia-pian-you-xi-by-leetcode/
 */
import java.util.HashSet;
import java.util.Set;

public class Solution822 {
    public int flipgame(int[] fronts, int[] backs) {
        Set<Integer> set=new HashSet<>();
        for (int i=0;i<fronts.length;i++){
            if (fronts[i]==backs[i]){
                set.add(fronts[i]);
            }
        }
        int ans=Integer.MAX_VALUE;
        for (int front : fronts) {
            if (!set.contains(front)){
                ans=Math.min(ans,front);
            }
        }
        for (int back : backs) {
            if (!set.contains(back)){
                ans=Math.min(ans,back);
            }
        }
        return ans==Integer.MAX_VALUE?0:ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution822().flipgame(new int[]{1,2,4,4,7},new int[]{1,3,4,1,3}));
    }
}
